package com.zjh.es;

import java.util.concurrent.Flow;
import java.util.concurrent.SubmissionPublisher;
public class PubisherUtilsDemo {
    static class Processor implements Flow.Processor<String, String> {
        @Override
        public void subscribe(Flow.Subscriber<? super String> subscriber) {

        }

        @Override
        public void onSubscribe(Flow.Subscription subscription) {

        }

        @Override
        public void onNext(String item) {

        }

        @Override
        public void onError(Throwable throwable) {

        }

        @Override
        public void onComplete() {

        }
    }
    public static void main(String[] args) throws InterruptedException {
        SubmissionPublisher<String> publisher = new SubmissionPublisher<>();



        Flow.Subscriber<String> subscriber = new Flow.Subscriber<>() {
            Flow.Subscription subscription;
            @Override
            public void onSubscribe(Flow.Subscription subscription) {
                this.subscription = subscription;
                subscription.request(1);
            }

            @Override
            public void onNext(String item) {
                System.out.println("收到数据：" + item);
                subscription.request(1);
            }
            @Override
            public void onError(Throwable throwable) {
                System.out.println("数据有误");
            }
            @Override
            public void onComplete() {
                System.out.println("数据接收完毕");
            }
        };
        publisher.subscribe(subscriber);
        publisher.submit("hello world");
        Thread.sleep(1000);
    }
}
